import pandas as pd
import openpyxl
import re
from datetime import datetime, timedelta
import send_email

# 读取Excel文件
file_path = 'labelExcel.xlsx'
df = pd.read_excel(file_path)

# 获取当前时间
current_now = datetime.now()

# 使用 iterrows 遍历 DataFrame 的每一行
for index, row in df.iterrows():
    
    # 使用正则表达式提取天数前面的数字
    interval = int(re.findall(r'\d+', df.at[index, df.columns[1]])[0])

    # 更新时间


    for counter in range(0, 7):
        num = [3,5,7,9,11,13,15]
        print(num[counter] + 1)

        update_time = current_now + timedelta(days = counter)
        current_time_start = update_time.strftime('%Y.%m.%d')
        current_time_end = (update_time + timedelta(days = interval - 1)).strftime('%Y.%m.%d')

        df.at[index, df.columns[num[counter]]] = current_time_start
        df.at[index, df.columns[num[counter] + 1]] = current_time_end
        if interval <= 3:
                df.at[index, df.columns[num[counter]]] = current_time_start + ' 9:00'
                df.at[index, df.columns[num[counter] + 1]] = current_time_end + ' 21:00'
        # if num[counter] + 1 == 17:
        #     break
            
        
# 保存更新后的文件
df.to_excel(file_path, index=False)

# 发送邮件
send_email.send_files_via_email("2698471124@qq.com", 
                                "dxnoogxmmquudgbi",
                                "2473042814@qq.com", 
                                [file_path],
                                "每周标签更新") 